//
//  blockOperation.swift
//  SwiftDemo
//
//  Created by Jason on 15/6/1.
//  Copyright (c) 2015年 Jason Jiang. All rights reserved.
//

import UIKit


typealias  finishBlock = (UIImage) -> Void
    
typealias  blockB = (Int,Int) -> (String) -> String

class blockOperation: NSOperation {
   
    var imgUrl : String!

    var block : finishBlock!
    var bk : blockB!
    
    override func start() {
        
        super.start()
    }
    
    override func main() {
        
        super.main()
        
        //start handle large data
        
        self.loadBigImg()
    }
    
    
    func loadBigImg(){
        NSLog("operation start")
        let url  = NSURL(string: imgUrl)!
        let data = NSData (contentsOfURL:url)
        let img = UIImage (data: data!)
        if let _ = img{
            
            dispatch_async(dispatch_get_main_queue(), { () -> Void in

                    self.block (img!)
                  let fc =  self.bk (2,3)
                
                let str = fc("sum:")
                NSLog("the str is %@",str)
            })
            
        }
        
    }
}
